<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" charset="UTF-8" src="//api.map.baidu.com/api?v=2.0&ak=hl9BYucS2r9XQAPWWnktcNQ2CQQOOK3b"></script>
    <script type="text/javascript" charset="UTF-8" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 110%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }

        #allmap{
            height: 450px;
            width: 100%;
            overflow: hidden;
            font-family: "微软雅黑";
            border:1px solid green;
        }

        /*百度地图搜索框定位*/
        .tangram-suggestion-main {
            z-index: 999999;
        }
        /*设置弹出框样式*/
        .el-dialog__body {
            padding: 0px 20px;
            color: #606266;
            font-size: 14px;
        }
        /**/
        /*.el-input--suffix .el-input__inner {
            width: 450px;
        }*/
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>首页<small>公司分布图</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <template>
            <el-tabs v-model="activeName"  @tab-click="handleClick">
                <el-tab-pane label="分布图" name="first">
                    <iframe name="right" class="el-main" src="map.html" width="100%" height="445px" frameborder="0"></iframe>
                </el-tab-pane>

                <el-tab-pane label="详细信息" name="second">
                    <div class="filter-container">
                        <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="address_detail" label="公司地址" align="center"></el-table-column>

                        <el-table-column prop="longitude" label="所在经度" align="center"></el-table-column>
                        <el-table-column prop="latitude" label="所在纬度" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <!--<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>-->
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增地址" :visible.sync="dialogFormVisible" @opened="createMap">

                            <div class="filter-container">
                                <el-input id="suggestId" name="address_detail" placeholder="请输入要查询的地址" v-model="address_detail"  style="width: 400px;"></el-input>
                                <el-button type="primary" @click="handleAdd()" class="butT">确定添加</el-button>
                            </div>
                            <!-- 地址：<input type="text" id="suggestId" name="address_detail" placeholder="请输入要查询的地址" v-model="address_detail" class="input_style">-->
                            <div id="allmap"></div>

                            <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
                        </el-dialog>
                    </div>

                </el-tab-pane>

            </el-tabs>
        </template>
    </div>
</div>
</body>


<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
            address_detail:'', //详细地址
            longitude:'',
            latitude:''
        },
        mounted () {
            this.createMap();
        },
        created() {
            this.findPage();
        },
        methods: {
            createMap(){
                var map = new BMap.Map("allmap");                //new 一个地图对象
                var point = new BMap.Point(104.066513, 30.572262);
                map.centerAndZoom(point, 15);

                map.enableScrollWheelZoom();                 //启用滚轮放大缩小
                map.enableContinuousZoom();         //启用地图惯性拖拽，默认禁用
                var geoc = new BMap.Geocoder();
                map.addEventListener("click",function(e){    //给地图添加点击事件
                    map.clearOverlays();
                    console.log(e);
                    var lng=e.point.lng;
                    var lat=e.point.lat;
                    console.log("lnglng",lng+"--------"+lat);
                    //创建标注位置
                    var pt = new BMap.Point(lng, lat);
                    var myIcon = new BMap.Icon("http://lbsyun.baidu.com/jsdemo/img/fox.gif", new BMap.Size(300,157));
                    var marker2 = new BMap.Marker(pt,{icon:myIcon});  // 创建标注
                    map.addOverlay(marker2);              // 将标注添加到地图中
                    // alert(e.point.lng + "," + e.point.lat);
                    vue.longitude = e.point.lng;
                    vue.latitude = e.point.lat;
                    // alert(this.longitude);
                    // alert(this.latitude);

                    geoc.getLocation(pt, function(rs){
                        var addComp = rs.address;
                        vue.address_detail = addComp;

                        //  alert("当前位置是:"+addComp);
                        console.log(rs)
                    });
                });
                // 关键字搜索
                function G(id) {
                    return document.getElementById(id);
                }


                var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
                    {"input" : "suggestId"
                        ,"location" : map
                    });

                ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
                    var str = "";
                    var _value = e.fromitem.value;
                    var value = "";
                    if (e.fromitem.index > -1) {
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

                    value = "";
                    if (e.toitem.index > -1) {
                        _value = e.toitem.value;
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
                    G("searchResultPanel").innerHTML = str;
                });

                var myValue;
                ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
                    var _value = e.item.value;
                    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

                    setPlace();
                });

                function setPlace(){
                    map.clearOverlays();    //清除地图上所有覆盖物
                    function myFun(){
                        var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
                        map.centerAndZoom(pp, 18);
                        map.addOverlay(new BMap.Marker(pp));    //添加标注
                    }
                    var local = new BMap.LocalSearch(map, { //智能搜索
                        onSearchComplete: myFun
                    });
                    local.search(myValue);
                }
            },
            //分页查询
            findPage() {
                var param = {
                    currentPage:this.pagination.currentPage,
                    pageSize:this.pagination.pageSize,
                    queryString:this.pagination.queryString
                };
                //发送ajax请求，提交分页相关参数
                axios.post("/address/findPage.do",param).then((res) => {
                    //为VUE对象的模型数据赋值，基于双向数据绑定展示到页面
                    this.dataList = res.data.rows;//当前页展示的数据集合
                    this.pagination.total = res.data.total;//总数据量
                });

            },
            // 重置表单
            resetForm() {
                this.formData = {};//重置数据
            },
            // 弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true;
                this.resetForm();
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit = true;

            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                //重新调用findPage方法进行分页查询
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                this.$confirm("你确定要删除当前数据吗？","提示",{//确认框
                    type:'warning'
                }).then(()=>{
                    //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                    axios.get("/address/delete.do?id=" + row.id).then((res) => {
                        if(res.data.flag){
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        }else{
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    });
                }).catch(()=>{
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    });
                });
            },
            handleAdd(){
                // alert("address_detail="+this.address_detail+"&longitude="+this.longitude+"&latitude="+this.latitude);
                //发送ajax请求，将表单数据提交到后台进行处理
              /*  axios.post("/address/add.do?address_detail="+vue.address_detail+"&longitude="+vue.longitude+"&latitude="+vue.latitude,this.formData).then((res) => {*/
                    //关闭新增窗口
                axios({
                    method:'POST',
                    url:'/address/add.do',
                    /*responseType:'arraybuffer',*/
                    data:{address_detail:vue.address_detail,
                        longitude:vue.longitude,
                        latitude:vue.latitude},
                }).then((res) => {
                    this.dialogFormVisible = false;
                    if(res.data.flag){
                        this.formData = this.data.data;
                        //操作成功
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                    }else{
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    //重新进行分页查询
                    this.findPage();
                });

            },
            handleClick(tab, event) {

            }
        }
    });
</script>


</html>
